package example.entities.stationary 
{
	import example.globals.Assets;
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.Graphic;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.Mask;
	import maskedpixel.ogmo.*;
	import maskedpixel.ogmo.utils.*;
	import net.flashpunk.masks.Grid;
	import net.flashpunk.utils.Draw;
	
	/**
	 * ...
	 * @author MaskedPixel
	 */
	public class Spikes extends Entity 
	{
		/**
		 * Which direction the spikes are facing.  This variable was registered with the Ogmo Project.
		 */
		public var facing:String;
		
		/**
		 * @inheritDoc
		 */
		public function Spikes(x:Number=0, y:Number=0, graphic:Graphic=null, mask:Mask=null) 
		{
			super(x, y, graphic, mask);
		}
		
		
		/**
		 * @inheritDoc
		 */
		override public function added():void
		{
			// Creates the graphic depending on which value facing was set to by they level loader.
			// This does nothing to "repeat" the graphic.
			switch(facing)
			{
				case "ground":
					graphic = new Image(Assets.SPIKES_GROUND_GFX);
					break;
				case "ceiling":
					graphic = new Image(Assets.SPIKES_CEILING_GFX);
					break;
				case "left":
					graphic = new Image(Assets.SPIKES_LEFT_GFX);
					break;
				case "right":
					graphic = new Image(Assets.SPIKES_RIGHT_GFX);
					break;
				default:
					graphic = null;
			}
			
			// Set the hitbox if width or height has a value in it.
			if (width || height)
			{
				// hardcoding 16 here is bad practice.  Find a better way, this is just demonstration.
				if (width) setHitbox(width, 16);
				else	setHitbox(16, height);
			}
		}
		
		/**
		 * Used to register this class with the Ogmo Project.
		 */
		public static function register():void
		{
			// -- create the spikes and the folder that contains them.
			// ---- create OgmoAttributes because they are reused.
			var tile:OgmoAttribute = new OgmoAttribute("tile", "1");
			var resizableX:OgmoAttribute = new OgmoAttribute("resizableX", "true");
			var resizableY:OgmoAttribute = new OgmoAttribute("resizableY", "true");
			// ---- ground
			var ground:OgmoObject = new OgmoObject("example.entities.stationary.Spikes", "spikes_ground", "spikes_ground.png", 16, 16);
			ground.registerAttribute(tile, resizableX);
			ground.registerValue(new OgmoValue(OgmoValue.STRING, "facing", "ground"));
			// ---- ceiling
			var ceiling:OgmoObject = new OgmoObject("example.entities.stationary.Spikes", "spikes_ceiling", "spikes_ceiling.png", 16, 16);
			ceiling.registerAttribute(tile, resizableX);
			ceiling.registerValue(new OgmoValue(OgmoValue.STRING, "facing", "ceiling"));
			// ---- left
			var left:OgmoObject = new OgmoObject("example.entities.stationary.Spikes", "spikes_left", "spikes_left.png", 16, 16);
			left.registerAttribute(tile, resizableY);
			left.registerValue(new OgmoValue(OgmoValue.STRING, "facing", "left"));
			// ---- right
			var right:OgmoObject = new OgmoObject("example.entities.stationary.Spikes", "spikes_right", "spikes_right.png", 16, 16);
			right.registerAttribute(tile, resizableY);
			right.registerValue(new OgmoValue(OgmoValue.STRING, "facing", "right"));
			// ---- folder
			var folder:OgmoFolder = new OgmoFolder("dangers", "spikes_ground.png");
			folder.registerObject(ground, ceiling, left, right);
			OgmoProject.registerFolder(folder);
		}
		
	}

}